<?php
if (!defined("IN_OP"))
{
    exit("You can't access this file directly...");
}
$lotto_id = intval($_GET['id']);
$userid = $curruser['id'];
$userlist = GetUserList($userid);
if ($userlist == "")
{
    exit("Not Users!");
    exit();
}
$conf = new Config();
$stopbet = $conf->get("waitbet");
if (!isset($_SESSION['saywaitmod']))
{
    $_SESSION['saywaitmod'] = 0;
}
$saystopmod = $_SESSION['saywaitmod'];
if ($stopbet <= date("Hi") && !$saystopmod)
{
    $saystopmod = 1;
    $_SESSION['saywaitmod'] = $saystopmod;
    echo "-1";
    exit();
}
$disk_code = "a";
$diskStr = "";
$split = 1;
$ratemod = 2;
include( "class_6h/BetTotal_6h.php" );
$BetTotal_6h = new BetTotal_6h($lotto_id);
$dataTotalArr = array();
$showDataArr = array();
$total_win = array();
$theacl = $curruser['acl'];
$userid = $curruser['id'];
$showid = $theacl == 255 ? "0" : $userid;
$betids = array(1002, 5, 6, 15, 16, 17, 23);
$bettypeStr = "1002,5,6,15,16,17,23";
$betsGame = "1002";
$totalBetTyprArr = array(5, 6);
$totalRs = $BetTotal_6h->getDataListTotal($lotto_id, "{$betsGame},5,6", $showid, $split, $diskStr);
while (!$totalRs->eof)
{
    $tempIdx = $totalRs->f['bettype'];
    $dataTotalArr[$tempIdx] = $totalRs->f;
    $totalRs->next();
}
$totalRs->close();
foreach ($betids as $betid)
{
    if (14 < $betid && $betid < 24)
    {
        switch ($betid)
        {
            case 15 :
                $jStart = "1";
                $jEnd = "3";
                break;
            case 16 :
                $jStart = "3";
                $jEnd = "5";
                break;
            case 17 :
                $jStart = "5";
                $jEnd = "8";
                break;
            case 23 :
                $jStart = "8";
                $jEnd = "10";
        }
        $i = 1;
        while ($i < 7)
        {
            $j = $jStart;
            while ($j < $jEnd)
            {
                $showDataArr["{$betid}_{$i}"]["{$i} {$j}"] = array("numbers" => "{$i} {$j}", "totalnum" => 0, "amount" => 0, "amount_rate" => 0, "rate" => 0, "back1" => 0, "back2" => 0, "winlost" => 0, "namount" => "");
                ++$j;
            }
            $dataTotalArr["{$betid}_{$i}"] = array("bettype" => "{$betid}_{$i}", "totalnum" => 0, "amount" => 0, "amount_rate" => 0, "back1" => 0, "back2" => 0);
            $total_win["{$betid}_{$i}"] = 0;
            ++$i;
        }
    }
    else
    {
        if ($betid == $betsGame)
        {
            $lostwin = array();
            if (isset($dataTotalArr[$betsGame]))
            {
                $winlost = ( $dataTotalArr[$betsGame]['amount'] - $dataTotalArr[$betsGame]['back1'] + $dataTotalArr[$betsGame]['back2'] ) / 6;
                $total_win[$betsGame] = $winlost;
            }
            else
            {
                $winlost = 0;
                $dataTotalArr[$betsGame] = array("bettype" => $betsGame, "totalnum" => 0, "amount" => 0, "amount_rate" => 0, "back1" => 0, "back2" => 0);
                $total_win[$betsGame] = 0;
            }
            $i = 1;
            while ($i < 50)
            {
                $showDataArr[$betsGame][$i] = array("numbers" => $i, "totalnum" => 0, "amount" => 0, "amount_rate" => 0, "rate" => 0, "back1" => 0, "back2" => 0, "winlost" => $winlost, "namount" => "");
                $lostwin[$betsGame][$i] = $winlost;
                ++$i;
            }
        }
        else
        {
            if (isset($dataTotalArr[5]))
            {
                $winlost5 = $dataTotalArr[5]['amount'] - $dataTotalArr[5]['back1'] + $dataTotalArr[5]['back2'];
            }
            else
            {
                $winlost5 = 0;
                $dataTotalArr[5] = array("bettype" => 5, "totalnum" => 0, "amount" => 0, "amount_rate" => 0, "back1" => 0, "back2" => 0);
            }
            if (isset($dataTotalArr[6]))
            {
                $winlost6 = $dataTotalArr[6]['amount'] - $dataTotalArr[6]['back1'] + $dataTotalArr[6]['back2'];
            }
            else
            {
                $winlost6 = 0;
                $dataTotalArr[6] = array("bettype" => 6, "totalnum" => 0, "amount" => 0, "amount_rate" => 0, "back1" => 0, "back2" => 0);
            }
            $showDataArr[5][1] = array("numbers" => 1, "totalnum" => 0, "amount" => 0, "amount_rate" => 0, "rate" => 0, "back1" => 0, "back2" => 0, "winlost" => $winlost5, "namount" => "");
            $showDataArr[5][2] = array("numbers" => 2, "totalnum" => 0, "amount" => 0, "amount_rate" => 0, "rate" => 0, "back1" => 0, "back2" => 0, "winlost" => $winlost5, "namount" => "");
            $showDataArr[6][1] = array("numbers" => 1, "totalnum" => 0, "amount" => 0, "amount_rate" => 0, "rate" => 0, "back1" => 0, "back2" => 0, "winlost" => $winlost6, "namount" => "");
            $showDataArr[6][2] = array("numbers" => 2, "totalnum" => 0, "amount" => 0, "amount_rate" => 0, "rate" => 0, "back1" => 0, "back2" => 0, "winlost" => $winlost6, "namount" => "");
            $total_win[5] = $winlost5;
            $total_win[6] = $winlost6;
        }
    }
}
$sql = $BetTotal_6h->getDataListByNumSsSQL($lotto_id, $bettypeStr, $showid, $diskStr, $split, $ratemod);
$rs = getdb($sql);
$updatetime = systime() - 30;
while (!$rs->eof)
{
    $bettype = $rs->f['bettype'];
    $winlost = 0;
    $i = $rs->f['numbers'];
    if ($betsGame == $bettype)
    {
        $i = intval($i);
        $winlost = ( $dataTotalArr[$bettype]['amount'] - $dataTotalArr[$bettype]['back1'] + $dataTotalArr[$rs->f[1]]['back2'] ) / 6 - $rs->f['amount_rate'];
        $lostwin[$bettype][$i] = $winlost;
        $total_win[$bettype] = $dataTotalArr[$bettype]['amount'] - $dataTotalArr[$bettype]['back1'] + $dataTotalArr[$bettype]['back2'];
    }
    else
    {
        if (in_array($bettype, $totalBetTyprArr))
        {
            $total_win[$bettype] = $dataTotalArr[$bettype]['amount'] - $dataTotalArr[$bettype]['back1'] + $dataTotalArr[$rs->f[1]]['back2'];
        }
        else
        {
            if (14 < $bettype && $bettype < 24)
            {
                $tempNumber = substr($i, 0, 1);
                $bettype = "{$bettype}_{$tempNumber}";
            }
            else
            {
                $i = intval($i);
            }
            $dataTotalArr[$bettype]['totalnum'] += $rs->f['totalnum'];
            $dataTotalArr[$bettype]['amount'] += $rs->f['amount'];
            $dataTotalArr[$bettype]['back1'] += $rs->f['back1'];
            $dataTotalArr[$bettype]['back2'] += $rs->f['back2'];
            $total_win[$bettype] = $dataTotalArr[$bettype]['amount'] - $dataTotalArr[$bettype]['back1'] + $dataTotalArr[$bettype]['back2'];
        }
    }
    $showDataArr[$bettype][$i]['totalnum'] = $rs->f['totalnum'];
    $showDataArr[$bettype][$i]['amount'] = $rs->f['amount'];
    $showDataArr[$bettype][$i]['amount_rate'] = $rs->f['amount_rate'];
    $showDataArr[$bettype][$i]['rate'] = $rs->f['rate'];
    $rs->next();
}
$rs->close();
$rs = getdb("select * from rate4a where lotto_id={$lotto_id}");
if ($rs->eof)
{
    exit("Error ID!");
}
$rs0 = get_srates_data($userid, $lotto_id, 4);
if ($rs0->eof)
{
    exit("Error ID!");
}
$i = 1;
while ($i < 50)
{
    $idx = d2($i);
    $showDataArr[$betsGame][$i]['rate'] = $rs->f["r{$idx}"] - $rs0->f["r{$idx}"] - 0;
    ++$i;
}
$rs->close();
$rs0->close();
$rs = getdb("select * from rate5a where lotto_id={$lotto_id}");
if ($rs->eof)
{
    exit("Error ID!");
}
$rs5 = get_srates_data($userid, $lotto_id, 5);
if ($rs5->eof)
{
    exit("Error ID!");
}
$showDataArr[5][1]['rate'] = $rs->f['r5_1'] - $rs5->f['r5_1'] - 0;
$showDataArr[5][2]['rate'] = $rs->f['r5_2'] - $rs5->f['r5_2'] - 0;
$showDataArr[6][1]['rate'] = $rs->f['r6_1'] - $rs5->f['r6_1'] - 0;
$showDataArr[6][2]['rate'] = $rs->f['r6_2'] - $rs5->f['r6_2'] - 0;
$rs->close();
$rs5->close();
$rs = getdb("select * from rate15a where lotto_id={$lotto_id}");
if ($rs->eof)
{
    exit("Error ID!");
}
$rs5 = get_srates_data($userid, $lotto_id, 23);
if ($rs5->eof)
{
    exit("Error ID!");
}
$i = 1;
while ($i < 7)
{
    $showDataArr["15_{$i}"]["{$i} 1"]['rate'] = $rs->f["r15_{$i}_1"] - $rs5->f["r15_{$i}_1"] - 0;
    $showDataArr["15_{$i}"]["{$i} 2"]['rate'] = $rs->f["r15_{$i}_2"] - $rs5->f["r15_{$i}_2"] - 0;
    $showDataArr["16_{$i}"]["{$i} 3"]['rate'] = $rs->f["r15_{$i}_3"] - $rs5->f["r15_{$i}_3"] - 0;
    $showDataArr["16_{$i}"]["{$i} 4"]['rate'] = $rs->f["r15_{$i}_4"] - $rs5->f["r15_{$i}_4"] - 0;
    $showDataArr["17_{$i}"]["{$i} 5"]['rate'] = $rs->f["r15_{$i}_5"] - $rs5->f["r15_{$i}_5"] - 0;
    $showDataArr["17_{$i}"]["{$i} 6"]['rate'] = $rs->f["r15_{$i}_6"] - $rs5->f["r15_{$i}_6"] - 0;
    $showDataArr["17_{$i}"]["{$i} 7"]['rate'] = $rs->f["r15_{$i}_7"] - $rs5->f["r15_{$i}_7"] - 0;
    $showDataArr["23_{$i}"]["{$i} 8"]['rate'] = $rs->f["r15_{$i}_8"] - $rs5->f["r15_{$i}_8"] - 0;
    $showDataArr["23_{$i}"]["{$i} 9"]['rate'] = $rs->f["r15_{$i}_9"] - $rs5->f["r15_{$i}_9"] - 0;
    ++$i;
}
$rs->close();
$rs5->close();
if (isset($showDataArr[$betsGame]) && 0 < $dataTotalArr[$betsGame]['amount'])
{
    asort($lostwin[$betsGame]);
    reset($lostwin[$betsGame]);
    $k = 1;
    $showDataArrTemp = array();
    foreach ($lostwin[$betsGame] as $key => $val)
    {
        $showDataArrTemp[$betsGame][$k] = $showDataArr[$betsGame][$key];
        ++$k;
    }
    $showDataArr[$betsGame] = $showDataArrTemp[$betsGame];
}
echo $total_win[$betsGame];
$i = 1;
while ($i < 50)
{
    echo "," . $showDataArr[$betsGame][$i]['numbers'] . "@" . $showDataArr[$betsGame][$i]['rate'] . "@" . $showDataArr[$betsGame][$i]['totalnum'] . "@" . $showDataArr[$betsGame][$i]['amount'];
    echo "@" . $showDataArr[$betsGame][$i]['amount_rate'];
    ++$i;
}
echo "\n";
echo $total_win[5];
$i = 1;
while ($i < 3)
{
    echo "," . $showDataArr[5][$i]['rate'] . "@" . $showDataArr[5][$i]['totalnum'] . "@" . $showDataArr[5][$i]['amount'];
    echo "@" . $showDataArr[5][$i]['amount_rate'];
    ++$i;
}
echo "\n";
echo $total_win[6];
$i = 1;
while ($i < 3)
{
    echo "," . $showDataArr[6][$i]['rate'] . "@" . $showDataArr[6][$i]['totalnum'] . "@" . $showDataArr[6][$i]['amount'];
    echo "@" . $showDataArr[6][$i]['amount_rate'];
    ++$i;
}
echo "\n";
$i = 1;
while ($i < 7)
{
    $tempIdx = "15_{$i}";
    echo $total_win[$tempIdx];
    echo "," . $showDataArr[$tempIdx]["{$i} 1"]['rate'] . "@" . $showDataArr[$tempIdx]["{$i} 1"]['totalnum'] . "@" . $showDataArr[$tempIdx]["{$i} 1"]['amount'];
    echo "@" . $showDataArr[$tempIdx]["{$i} 1"]['amount_rate'];
    echo "," . $showDataArr[$tempIdx]["{$i} 2"]['rate'] . "@" . $showDataArr[$tempIdx]["{$i} 2"]['totalnum'] . "@" . $showDataArr[$tempIdx]["{$i} 2"]['amount'];
    echo "@" . $showDataArr[$tempIdx]["{$i} 2"]['amount_rate'];
    echo "\n";
    $tempIdx = "16_{$i}";
    echo $total_win[$tempIdx];
    echo "," . $showDataArr[$tempIdx]["{$i} 3"]['rate'] . "@" . $showDataArr[$tempIdx]["{$i} 3"]['totalnum'] . "@" . $showDataArr[$tempIdx]["{$i} 3"]['amount'];
    echo "@" . $showDataArr[$tempIdx]["{$i} 3"]['amount_rate'];
    echo "," . $showDataArr[$tempIdx]["{$i} 4"]['rate'] . "@" . $showDataArr[$tempIdx]["{$i} 4"]['totalnum'] . "@" . $showDataArr[$tempIdx]["{$i} 4"]['amount'];
    echo "@" . $showDataArr[$tempIdx]["{$i} 4"]['amount_rate'];
    echo "\n";
    $tempIdx = "17_{$i}";
    echo $total_win[$tempIdx];
    echo "," . $showDataArr[$tempIdx]["{$i} 5"]['rate'] . "@" . $showDataArr[$tempIdx]["{$i} 5"]['totalnum'] . "@" . $showDataArr[$tempIdx]["{$i} 5"]['amount'];
    echo "@" . $showDataArr[$tempIdx]["{$i} 5"]['amount_rate'];
    echo "," . $showDataArr[$tempIdx]["{$i} 6"]['rate'] . "@" . $showDataArr[$tempIdx]["{$i} 6"]['totalnum'] . "@" . $showDataArr[$tempIdx]["{$i} 6"]['amount'];
    echo "@" . $showDataArr[$tempIdx]["{$i} 6"]['amount_rate'];
    echo "," . $showDataArr[$tempIdx]["{$i} 7"]['rate'] . "@" . $showDataArr[$tempIdx]["{$i} 7"]['totalnum'] . "@" . $showDataArr[$tempIdx]["{$i} 7"]['amount'];
    echo "@" . $showDataArr[$tempIdx]["{$i} 7"]['amount_rate'];
    echo "\n";
    $tempIdx = "23_{$i}";
    echo $total_win[$tempIdx];
    echo "," . $showDataArr[$tempIdx]["{$i} 8"]['rate'] . "@" . $showDataArr[$tempIdx]["{$i} 8"]['totalnum'] . "@" . $showDataArr[$tempIdx]["{$i} 8"]['amount'];
    echo "@" . $showDataArr[$tempIdx]["{$i} 8"]['amount_rate'];
    echo "," . $showDataArr[$tempIdx]["{$i} 9"]['rate'] . "@" . $showDataArr[$tempIdx]["{$i} 9"]['totalnum'] . "@" . $showDataArr[$tempIdx]["{$i} 9"]['amount'];
    echo "@" . $showDataArr[$tempIdx]["{$i} 9"]['amount_rate'];
    echo "\n";
    ++$i;
}
include( "class_6h/class.menu.php" );
$fieldArr = array("lotto_id" => $lotto_id, "split_id" => 1);
$onlineMenu = new menu_6h(11, $fieldArr);
echo $onlineMenu->getMenuAmu();
echo "\n";
exit();